home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / test / test10.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  3KB  |  135 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #ifdef __sgi
  9. #include <malloc.h>
  10. #endif
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <GL/glut.h>
  14.  
  15. /* XXX As a test of 16-bit font support in capturexfont, I made
  16.    a font out of the 16-bit Japanese font named
  17.    '-jis-fixed-medium-r-normal--24-230-75-75-c-240-jisx0208.1'
  18.    and tried it out.  Defining JIS_FONT uses it in this test. */
  19. /* #define JIS_FONT */
  20.  
  21. #ifdef JIS_FONT
  22. extern void *glutBitmapJis;
  23. #endif
  24.  
  25. int ch = -2;
  26. void *fonts[] =
  27. {
  28.   GLUT_BITMAP_TIMES_ROMAN_24,
  29.   GLUT_BITMAP_TIMES_ROMAN_10,
  30.   GLUT_BITMAP_9_BY_15,
  31.   GLUT_BITMAP_8_BY_13,
  32.   GLUT_BITMAP_HELVETICA_10,
  33.   GLUT_BITMAP_HELVETICA_12,
  34.   GLUT_BITMAP_HELVETICA_18,
  35. #ifdef JIS_FONT
  36.   &glutBitmapJis
  37. #endif
  38. };
  39. void *names[] =
  40. {
  41.   "Times Roman 24",
  42.   " Times Roman 10",
  43.   "  9 by 15",
  44.   "   8 by 13",
  45.   "    Helvetica 10",
  46.   "     Helvetica 12",
  47.   "      Helvetica 18",
  48. #ifdef JIS_FONT
  49.   "    Mincho JIS"
  50. #endif
  51. };
  52. #define NUM_FONTS (sizeof(fonts)/sizeof(void*))
  53. int font = 0;
  54.  
  55. void
  56. tick(void)
  57. {
  58.   static int limit = 270;
  59.  
  60.   ch += 5;
  61.   if (ch > limit) {
  62.     ch = -2;
  63.     font++;
  64. #ifdef JIS_FONT
  65.     if (font == 4) {
  66.       limit = 0x747e;
  67.       ch = 0x2121;
  68.     }
  69. #endif
  70.     if (font == NUM_FONTS) {
  71.       printf("PASS: test10\n");
  72.       exit(0);
  73.     }
  74.   }
  75.   glutPostRedisplay();
  76. }
  77.  
  78. void
  79. output(int x, int y, char *msg)
  80. {
  81.   glRasterPos2f(x, y);
  82.   while (*msg) {
  83.     glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *msg);
  84.     msg++;
  85.   }
  86. }
  87.  
  88. void
  89. display(void)
  90. {
  91.   glutIdleFunc(tick);
  92.   glClear(GL_COLOR_BUFFER_BIT);
  93.   glRasterPos2f(0, 0);
  94.   glutBitmapCharacter(fonts[font], ch);
  95.   glRasterPos2f(30, 30);
  96.   glutBitmapCharacter(fonts[font], ch + 1);
  97.   glRasterPos2f(-30, -30);
  98.   glutBitmapCharacter(fonts[font], ch + 2);
  99.   glRasterPos2f(30, -30);
  100.   glutBitmapCharacter(fonts[font], ch + 3);
  101.   glRasterPos2f(-30, 30);
  102.   glutBitmapCharacter(fonts[font], ch + 4);
  103.   glRasterPos2f(0, 30);
  104.   glutBitmapCharacter(fonts[font], ch + 5);
  105.   glRasterPos2f(0, -30);
  106.   glutBitmapCharacter(fonts[font], ch + 6);
  107.   glRasterPos2f(-30, 0);
  108.   glutBitmapCharacter(fonts[font], ch + 7);
  109.   glRasterPos2f(30, 0);
  110.   glutBitmapCharacter(fonts[font], ch + 8);
  111.   output(-48, -48, names[font]);
  112.   glutSwapBuffers();
  113. }
  114.  
  115. int
  116. main(int argc, char **argv)
  117. {
  118. #if defined(__sgi)  && !defined(REDWOOD)
  119.   /* XXX IRIX 6.0.1 mallopt(M_DEBUG, 1) busted. */
  120.   mallopt(M_DEBUG, 1);
  121. #endif
  122.   glutInit(&argc, argv);
  123.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  124.   glutInitWindowSize(200, 200);
  125.   glutCreateWindow("Test bitmap fonts");
  126.   glMatrixMode(GL_PROJECTION);
  127.   glLoadIdentity();
  128.   gluOrtho2D(-50, 50, -50, 50);
  129.   glClearColor(0.0, 0.0, 0.0, 1.0);
  130.   glColor3f(1.0, 1.0, 1.0);
  131.   glutDisplayFunc(display);
  132.   glutMainLoop();
  133.   return 0;             /* ANSI C requires main to return int. */
  134. }
  135.